package route

import (
	"My_Blog02/api"
	"My_Blog02/middleware"
	"My_Blog02/utils"
	"github.com/gin-gonic/gin"
)

func InitRoutes() {
	gin.SetMode(utils.AppMode)
	r := gin.New()
	r.Use(gin.Recovery())
	r.Use(middleware.Logger())
	r.GET("/getArticle/:id", api.SearchArticle) //获取文章
	r.POST("/addUser", api.AddUser)             //添加用户
	r.GET("/getUser/:id", api.GetUser)          //查询用户
	r.POST("/login", api.Login)                 //登录

	auth := r.Group("v1")
	auth.Use(middleware.JwtToken())
	{

		auth.POST("/addArticle", api.AddArticle)             //增加文章
		auth.DELETE("/deleteArticle/:id", api.DeleteArticle) //删除文章
		auth.PUT("/modifyArticle/:id", api.ModifyArticle)    //修改文章

		auth.DELETE("/deleteUser/:id", api.DeleteUser) //删除用户
		auth.PUT("/modifyUser/:id", api.ModifyUser)    //修改用户

	}

	err := r.Run(utils.HttpPort)
	if err != nil {
		panic(err)
	}
}
